var gulp = require('gulp');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var header = require('gulp-header');
var merge = require('gulp-merge');
var templatizer = require('templatizer');
var pkg = require('./package.json');

var banner =
    '/* Maxthon-Session-Manager created by NoAnyLove (www.noanylove.com) */ \n';

gulp.task('templatizer', function () {
    templatizer(__dirname + '/src/jade-templates', __dirname +
        '/src/_templates.js', {
            jade: {
                doctype: 'html'
            }
        })
});

gulp.task('jshint', function () {
    gulp.src(['src/*.js', 'Init*.js', '!src/_*.js'])
        .pipe(jshint({
            laxbreak: true,
            evil: true
        }))
        .pipe(jshint.reporter('default'));
});

gulp.task('minify', ['templatizer'], function () {
    gulp.src('src/*.js')
        .pipe(uglify({
            preserveComments: 'some'
        }))
        .pipe(concat('all.min.js'))
        .pipe(header(banner))
        .pipe(gulp.dest('build'));
});

gulp.task('watch', function () {
    gulp.watch('src/jade-templates/*', ['templatizer']);
});

gulp.task('default', ['templatizer', 'jshint', 'minify']);